package com.suixun.controller;

import java.sql.SQLException;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.authority.controller.BaseManager;
import com.google.gson.Gson;
import com.suixun.entity.form.StudentForm;
import com.suixun.service.impl.StudentServiceImpl;
import com.suixun.util.Constant;
import com.suixun.util.StringUtil;
/**
 * 
 * <p>Title: StudentController</p>
 * <p> 功能描述:学生信息管理服务 </p> 
 * @author	陈显强
 * @date	2016年12月12日下午5:39:07
 * @version 1.0
 */
@Controller
@RequestMapping("/studentInfoManage")
public class StudentController extends BaseManager {
	@Resource
	private StudentServiceImpl studentService;
	/**
	 * 
	 * <p>Title: queryStudentList</p>
	 * <p> 功能描述:查询学生信息 </p>
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/queryStduentList.json")
	public Object queryStudentList(String param){
		if(!checkRight()){
			return fail(Constant.Authority.CHECK_FALSE);
		}
		try {
			StudentForm student=new Gson().fromJson(param, StudentForm.class);
			return success(studentService.queryList(student));
		} catch (SQLException e) {
			logger("StudentController queryStudentList:"+e.getMessage(),e);
			return fail(Constant.EXCEPTION.OPERATE_FAIL);
		}
	}
	/**
	 * 
	 * <p>Title: queryStudent</p>
	 * <p> 功能描述:通过设备号查询学生信息 </p>
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/queryStduent.json")
	public Object queryStudent(String param){
		if (param==null) {
			return fail(Constant.EMPTY);
		}
		try {
			StudentForm student=new Gson().fromJson(param, StudentForm.class);
			boolean isParam = StringUtil.isEmpty(student.getMdtid()) && StringUtil.isEmpty(student.getSimid());
			if(student==null || isParam){
				return fail(Constant.EMPTY);
			}
			return success(studentService.queryByParam(student));
		} catch (Exception e) {
			logger("StudentController queryStudent:"+e.getMessage(),e);
			return fail(Constant.EXCEPTION.OPERATE_FAIL);
		}
	}
}
